<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单列表')" />
</head>
<body class="gray-bg" onload='init()'>
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>订单号：</label>
                                <input type="text" name="orderNo"/>
                            </li>
                            <li>
                                <label>支付订单：</label>
                                <input type="text" name="payNo"/>
                            </li>
                            <li>
                                <label>支付方式：</label>
                                <select name="payType">
                                    <option value="">所有</option>
                                    <option value="alipay">支付宝</option>
                                    <option value="wxpay">微信</option>
                                </select>
                            </li>
                            <li>
                                <label>订单状态：</label>
                                <select name="status" th:with="type=${@dict.getType('sys_order_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue =='1'}"></option>
                                </select>
                            </li>
                            <li>
                                <label>用户标识：</label>
                                <input type="text" name="userIdentify"/>
                            </li>
                            <li>
                                <label>用户账号：</label>
                                <input type="text" name="account"/>
                            </li>
                            <li>
                                <label>用户邮箱：</label>
                                <input type="text" name="email"/>
                            </li>
                            <li>
                                <label>用户性别：</label>
                                <input type="text" name="sex"/>
                            </li>
                            <li>
                                <label>用户年龄：</label>
                                <input type="text" name="email"/>
                            </li>
                            <li>
                                <label>所在地区：</label>
                                <input type="text" name="email"/>
                            </li>
                            <li>
                                <label>设备标识：</label>
                                <input type="text" name="deviceIdentify"/>
                            </li>
                            <li>
                                <label>手机品牌：</label>
                                <select name="phoneBrand" id="phoneBrand" onchange="selectPhoneBrand()">
                                    <option value="">请选择手机品牌</option>
                                    <option th:each="phoneBrand:${phoneBrandList}" th:text="${phoneBrand}" th:value="${phoneBrand}" ></option>
                                </select>
                            </li>
                            <li>
                                <label>安卓版本：</label>
                                <select name="androidVersion" id="androidVersion">
                                    <option value="">请选择安卓版本</option>
                                </select>
                            </li>
                            <li>
                                <label>手机型号：</label>
                                <select name="phoneModel" id="phoneModel">
                                    <option value="">请选择手机型号</option>
                                    <option th:each="phoneModel:${phoneModelList}" th:text="${phoneModel}" th:value="${phoneModel}" ></option>
                                </select>
                            </li>
                            <li>
                                <label>渠道：</label>
                                <select name="channelId">
                                    <option value="">请选择渠道</option>
                                    <option th:each="channel:${channelList}" th:text="${channel.name}" th:value="${channel.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>应用名称：</label>
                                <select name="productId" id="productId" onchange="selectGoodType()">
                                    <option value="">请选择应用</option>
                                    <option th:each="product:${productList}" th:text="${product.name}" th:value="${product.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>服务名称：</label>
                                <select id="goodsTypeId" name="goodsTypeId"  onchange="selectGoods()">
                                    <option value="">请选择服务</option>
                                </select>
                            </li>
                            <li>
                                <label>套餐名称：</label>
                                <select id="goodsId" name="goodsId">
                                    <option value="">请选择服务套餐</option>
                                </select>
                            </li>
                            <li>
                                开始时间：
                                <input type="text" class="time-input" placeholder="请选择开始时间" id="startCreateTime" name="startCreateTime" th:value="${#dates.format(startCreateTime, 'yyyy-MM-dd')}"/>
                            </li>
                            <li>
                                截止时间：
                                <input type="text" class="time-input" placeholder="请选择结束时间" id="endCreateTime" name="endCreateTime" th:value="${#dates.format(endCreateTime, 'yyyy-MM-dd')}"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;查询</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="privateReset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="product:order:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="product:order:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="product:order:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="product:order:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('product:order:edit')}]];
        var removeFlag = [[${@permission.hasPermi('product:order:remove')}]];
        var orderStatus = [[${@dict.getType('sys_order_status')}]];
        var userSex = [[${@dict.getType('sys_user_sex')}]];
        var prefix = ctx + "product/order";

        window.onload = function() {
            timeInit();
        }

        function timeInit() {
            var date = $.common.dateFormat(new Date(), "yyyy-MM-dd");
            $('#startCreateTime').val(date);
            $('#endCreateTime').val(date);
        }

        function privateReset() {
            $.form.reset();
            timeInit();
        }

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/form",
                updateUrl: prefix + "/form/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "订单",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '${comment}',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '订单号'
                },
                {
                    field: 'payNo',
                    title: '支付订单号'
                },
                {
                    field: 'amount',
                    title: '金额'
                },
                {
                    field: 'productName',
                    title: '应用名称'
                },
                {
                    field: 'productVersion',
                    title: '应用版本号'
                },
                {
                    field: 'goodsTypeName',
                    title: '服务名称'
                },
                {
                    field: 'goodsName',
                    title: '服务套餐名称'
                },
                {
                    field: 'payType',
                    title: '支付方式',
                    formatter: function(value, row, index) {
                        if(value == "alipay"){
                            return "支付宝";
                        }else if(value == "wxpay"){
                            return "微信";
                        }
                        return "";
                    }
                },
                {
                    field: 'userIdentify',
                    title: '用户标识',
                    formatter: function(value, row, index) {
                        if (value != null) {
                            return '<a href="javascript:void(0)" onclick="detail(\'' + row.userId + '\')">' + value + '</a>';
                        }
                    }
                },
                {
                    field: 'account',
                    title: '用户账号'
                },
                {
                    field: 'email',
                    title: '用户邮箱'
                },
                {
                    field: 'sex',
                    title: '用户性别',
                    formatter: function(value, row, index) {
                        if (value == 0) {
                            return "女";
                        } else if (value == 1) {
                            return "男";
                        } else if (value == 2) {
                            return "未知";
                        } else {
                            return "未知";
                        }
                    },
                    width: 50
                },
                {
                    field: 'birthday',
                    title: '用户出生日期'
                },
                {
                    field: 'provinceCode',
                    title: '省'
                },
                {
                    field: 'cityCode',
                    title: '市'
                },
                {
                    field: 'countyCode',
                    title: '县区'
                },
                {
                    field: 'address',
                    title: '用户所在地区'
                },
                {
                    field: 'deviceIdentify',
                    title: '设备标识',
                    formatter: function(value, row, index) {
                        if (value != null) {
                            return '<a href="javascript:void(0)" onclick="deviceDetail(\'' + row.deviceId + '\')">' + value + '</a>';
                        }
                    }
                },
                {
                    field: 'phoneBrand',
                    title: '手机品牌'
                },
                {
                    field: 'phoneModel',
                    title: '手机型号'
                },
                {
                    field: 'resolvingPower',
                    title: '分辨率'
                },
                {
                    field: 'channelName',
                    title: '渠道'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(orderStatus, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function selectGoodType() {
            var productId = $("#productId").val();
            $.ajax({
                type: "GET",
                url: ctx + "/product/order/addChangeProduct?productId="+productId,
                cache: false,
                dataType: 'json',
                success: function(result) {
                    if (result) {
                        var html = "<option value=''>请选择服务</option>";
                        for (var i = 0; i < result.length; i++) {
                            html += "<option value='" + result[i].id + "'>" + result[i].name + "</option>"
                        }
                        $('#goodsTypeId').html(html);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("失败。");
                }
            });
        }
        function selectGoods() {
            var goodsTypeId = $("#goodsTypeId").val();
            $.ajax({
                type: "GET",
                url: ctx + "/product/order/addChangeGoodType?goodTypeId="+goodsTypeId,
                cache: false,
                dataType: 'json',
                success: function(result) {
                    if (result) {
                        var html = "<option value=''>请选择服务</option>";
                        for (var i = 0; i < result.length; i++) {
                            html += "<option value='" + result[i].id + "'>" + result[i].name + "</option>"
                        }
                        $('#goodsId').html(html);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("失败。");
                }
            });
        }
        function selectPhoneBrand() {
            var phoneBrand = $("#phoneBrand").val();
            $.ajax({
                type: "GET",
                url:  ctx + "product/deviceStatis/addChangePhoneBrand?phoneBrand="+phoneBrand,
                cache: false,
                dataType: 'json',
                success: function(result) {
                    if (result) {
                        var html = "<option value=''>请选择安卓版本</option>";
                        for (var i = 0; i < result.length; i++) {
                            html += "<option value='" + result[i] + "'>" + result[i] + "</option>"
                        }
                        $('#androidVersion').html(html);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("失败。");
                }
            });
        }
        function detail(id) {
            $.modal.open("查看用户信息",ctx + "product/device/getUserInfo/"+id);
        }
        function deviceDetail(id) {
            $.modal.open("查看设备信息",ctx + "product/device/getDeviceInfo/"+id);
        }
    </script>
</body>
</html>